﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class TAMEINST
    {
        public TAMEINST()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VAMEINST();
            this.DataContext = MV;
            InitializeComponent();
        }

        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            base.QueryCommand(sender, e);
        }

        public override void NewCommand(object sender, RoutedEventArgs e)
        { 
            base.NewCommand(sender, e);
        }

        public override void DeleteCommand(object sender, RoutedEventArgs e)
        {
          
            base.DeleteCommand(sender, e);
        }

        public override void SaveCommand(object sender, RoutedEventArgs e)
        {
           
            base.SaveCommand(sender, e);
        }

        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {

        }
     
        public override void OnBDEKENChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            if (BDEKEN.Length < 8)
                return;
            TMV.AMEBDEKEN = Helpers.Helper.Left(BDEKEN.Trim().PadRight(8), 8);
            cZL06.vwMaster.View.MoveCurrentTo(-1);
            base.OnBDEKENChg();
        }
        public override void OnBDEMODChg()
        {
            if (!IsEdit)
                return;
            if (BDEMOD.Length < 6)
                return;
            dwData = TBMain.NewRow();
            dwData["AMEMANDANT"] = app.Mandant;
            dwData["AMENRKRS"] = KRS;
            dwData["AMELFDNR"] = LFD;
            dwData["AMEPOS"] = POS;
            dwData["AMEMODNR"] = MODNR;
            TMV.DAME03(dwData);
            dwData = TBMain.NewRow();
            dwData["AMEMANDANT"] = app.Mandant;
            dwData["AMEBDEKEN"] = " AND SUBSTR(AMEBDEKEN,1,6)='" + BDEMOD + "'";
            dwData["AMEBEZ"] = "AND AMART LIKE 'ZLAN%'";
            SResult = TMV.QAME06(dwData);
            dwData = TBMain.NewRow();
            TMV.SetUpNewRow(ref dwData);
            dwData["AMEMANDANT"] = app.Mandant;
            dwData["AMENRKRS"] = KRS;
            dwData["AMELFDNR"] = LFD;
            dwData["AMEPOS"] = POS;
            dwData["AMEMODNR"] = MODNR;
            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                dwData["AMEEINSTNR"] = row["AMEEINSTNR"];
                dwData["AMEBDEKEN"] = row["AMEBDEKEN"];
                dwData["AMEBEZ"] = row["AMEBEZ"];
                dwData["AMEKBEZ"] = row["AMEKBEZ"];
                dwData["AMEINTERVAL"] = row["AMEINTERVAL"];
                TMV.InsertAMEINST(dwData);
            }
            string auf = EXAUF;
            EXAUF = "";
            EXAUF = auf;
            cZL05.vwMaster.View.MoveCurrentTo(-1);
            base.OnBDEMODChg();
        }
      
    }
}
